package com.aspose.cells.a.d;

public class zaa extends zfw {
   public int a;
   public int b;
   public int c;
   public int d;
   public int e;
   public int f;
   public int g;
   public int[] h;
   public int[] i;
   public int[] j;
   public int[] k;
   public int[] l;

   public zaa(zu var1) throws Exception {
      int var2 = (int)var1.a().i();
      int var3 = var1.e() & '\uffff';
      if (var3 != 0) {
         throw new IllegalStateException("Unexpected cmap table version.");
      } else {
         int var4 = var1.e() & '\uffff';

         for(int var5 = 0; var5 < var4; ++var5) {
            this.a = var1.e() & '\uffff';
            this.b = var1.e() & '\uffff';
            int var6 = var1.b();
            if (this.a == 3 && (this.b == 1 || this.b == 0)) {
               int var7 = (int)var1.a().i();
               int var8 = var2 + var6;
               var1.a().b((long)var8);
               int var9 = var1.e() & '\uffff';
               if (var9 == 4) {
                  var1.a().b((long)var8);
                  this.a(var1);
                  return;
               }

               var1.a().b((long)var7);
            }
         }

         throw new IllegalStateException("Cannot find a required cmap table.");
      }
   }

   private void a(zu var1) throws Exception {
      int var2 = (int)var1.a().i();
      byte var3 = 4;
      int var4 = var1.e() & '\uffff';
      if (var4 != 4) {
         throw new IllegalStateException("Unexpected cmap subtable format.");
      } else {
         int var5 = var1.e() & '\uffff';
         this.c = var1.e() & '\uffff';
         this.d = var1.e() & '\uffff';
         this.e = var1.e() & '\uffff';
         this.f = var1.e() & '\uffff';
         this.g = var1.e() & '\uffff';
         int var6 = this.d / 2;
         this.h = a(var1, var6);
         var1.e();
         this.i = a(var1, var6);
         this.j = b(var1, var6);
         this.k = a(var1, var6);
         int var7 = var2 + var5;
         int var8 = var7 - (int)var1.a().i();
         int var9 = var8 / 2;
         if ((long)(var7 + var3) <= var1.a().h()) {
            var9 += var3 / 2;
         }

         this.l = a(var1, var9);
      }
   }

   public zfv a(zbf var1, String var2) {
      zfv var3 = new zfv();
      int var4 = this.h.length;

      for(int var5 = 0; var5 < var4; ++var5) {
         for(int var6 = this.i[var5]; var6 <= this.h[var5]; ++var6) {
            int var7;
            if (var6 == 65535) {
               var7 = 0;
            } else {
               int var8 = this.k[var5];
               switch(var8) {
               case 0:
                  var7 = var6 + this.j[var5] & '\uffff';
                  if (var7 == 65535) {
                     var7 = 0;
                  }
                  break;
               case 65535:
                  var7 = 0;
                  break;
               default:
                  int var9 = var6 - this.i[var5];
                  int var10 = this.k[var5] / 2 + var9 - var4 + var5;
                  var7 = this.l[var10];
                  if (var7 != 0) {
                     var7 = var7 + this.j[var5] & '\uffff';
                  }
               }
            }

            zbe var12 = var1.a(var7);
            long var13 = (long)var6;
            if (var1.a.length < 255 && var6 > 61440 && var6 != 65535) {
               var13 &= 4095L;
            }

            zfu var11 = new zfu((char)((int)var13), var7, var12.a & '\uffff', var12.b);
            var3.b(var11);
            if (var11.b() == 0) {
               var3.a(var11);
            }
         }
      }

      return var3;
   }

   public void a(zfj var1) {
      int var2 = var1.a() - 1;
      if (var1.d(var2) != 65535) {
         throw new IllegalStateException("Last character is supposed to be the 0xffff (the missing character).");
      } else if ((Integer)var1.c(var2) != 0) {
         throw new IllegalStateException("Glyph index for the missing character is expected to be zero.");
      } else {
         int var3 = var1.a();
         this.d = var3 * 2;
         this.e = 2 << (int)Math.floor(Math.log((double)var3) / Math.log(2.0D));
         this.f = (int)(Math.log((double)this.e / 2.0D) / Math.log(2.0D));
         this.g = 2 * var3 - this.e;
         this.h = new int[var3];
         this.i = new int[var3];
         this.j = new int[var3];
         this.k = new int[var3];
         this.l = new int[0];

         for(int var4 = 0; var4 < var1.a(); ++var4) {
            int var5 = var1.d(var4);
            int var6 = (Integer)var1.c(var4);
            this.h[var4] = var5;
            this.i[var4] = var5;
            this.j[var4] = var6 - var5;
         }

      }
   }

   public void a(zv var1) throws Exception {
      var1.b(0);
      var1.b(1);
      var1.b(this.a);
      var1.b(this.b);
      var1.a(12L);
      this.b(var1);
   }

   private void b(zv var1) throws Exception {
      int var2 = (int)var1.a().i();
      var1.b(4);
      int var3 = 16 + this.d * 4 + this.l.length * 2;
      var1.b(var3);
      var1.b(this.c);
      var1.b(this.d);
      var1.b(this.e);
      var1.b(this.f);
      var1.b(this.g);
      a(this.h, var1);
      var1.b(0);
      a(this.i, var1);
      a(this.j, var1);
      a(this.k, var1);
      a(this.l, var1);
   }

   private static int[] a(zu var0, int var1) throws Exception {
      int[] var2 = new int[var1];

      for(int var3 = 0; var3 < var1; ++var3) {
         var2[var3] = var0.e() & '\uffff';
      }

      return var2;
   }

   private static int[] b(zu var0, int var1) throws Exception {
      int[] var2 = new int[var1];

      for(int var3 = 0; var3 < var1; ++var3) {
         var2[var3] = var0.d();
      }

      return var2;
   }

   private static void a(int[] var0, zv var1) throws Exception {
      int[] var2 = var0;
      int var3 = var0.length;

      for(int var4 = 0; var4 < var3; ++var4) {
         int var5 = var2[var4];
         var1.b(var5);
      }

   }
}
